home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
cal-tex.el
(
.txt
)
< prev
next >
Wrap
LaTeX Document
|
1996-07-02
|
63KB
|
1,452 lines
;;; cal-tex.el --- calendar functions for printing calendars with LaTeX.
;; Copyright (C) 1995 Free Software Foundation, Inc.
;; Author: Steve Fisk <fisk@bowdoin.edu>
;; Edward M. Reingold <reingold@cs.uiuc.edu>
;; Keywords: calendar
;; Human-Keywords: Calendar, LaTeX
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This collection of functions implements the creation of LaTeX calendars
;; based on the user's holiday choices and diary file.
;; TO DO
;; (*) Add holidays and diary entries to daily calendar.
;; (*) Add diary entries to weekly calendar functions.
;; (*) Make calendar styles for A4 paper.
;; (*) Make daily and monthly styles Filofax paper.
;; (*) Improve the LaTeX command that produces the boxes in the monthly
;; calendar to eliminate slight gap--what causes it?!
;;; Code:
(require 'calendar)
(autoload 'list-diary-entries "diary-lib" nil t)
(autoload 'calendar-holiday-list "holidays" nil t)
(autoload 'calendar-iso-from-absolute "cal-iso" nil t)
;;; Customizable variables
(defvar cal-tex-which-days '(0 1 2 3 4 5 6)
"*The days of the week that are displayed on the portrait monthly calendar.
Sunday is 0, Monday is 1, and so on. The default is to print from Sunday to
Saturday. For example, use
(setq cal-tex-which-days '(1 3 5))
to only print Monday, Wednesday, Friday.")
(defvar cal-tex-holidays t
"*If t (default), then the holidays are also printed.
If finding the holidays is too slow, set this to nil.")
(defvar cal-tex-diary nil
"*If t, the diary entries are printed in the calendar.")
(defvar cal-tex-daily-string
'(let* ((year (extract-calendar-year date))
(day (calendar-day-number date))
(days-remaining (- (calendar-day-number (list 12 31 year)) day)))
(format "%d/%d" day days-remaining))
"*An expression in the variable `date' whose value is placed on date.
The string resulting from evaluating this expression is placed at the bottom
center of `date' on the monthly calendar, next to the date in the weekly
calendars, and in the top center of daily calendars.
Default is ordinal day number of the year and the number of days remaining.
As an example of what you do, setting this to
'(progn
(require 'cal-hebrew)
(calendar-hebrew-date-string date))
will put the Hebrew date at the bottom of each day.")
(defvar cal-tex-buffer "calendar.tex"
"*The name for the tex-ed calendar.")
(defvar cal-tex-24 nil
"*If t, use a 24 hour clock in the daily calendar.")
(defvar cal-tex-daily-start 8
"*The first hour of the daily calendar page.")
(defvar cal-tex-daily-end 20
"*The last hour of the daily calendar page.")
;;; Definitions for LaTeX code
(defvar cal-tex-day-prefix "\\caldate{%s}{%s}"
"The initial LaTeX code for a day.
The holidays, diary entries, bottom string, and the text follow.")
(defvar cal-tex-day-name-format "\\myday{%s}%%"
"The format for LaTeX code for a day name. The names are taken from
calendar-day-name-array.")
(defvar cal-tex-cal-one-month
"\\def\\calmonth#1#2%
{\\begin{center}%
\\Huge\\bf\\uppercase{#1} #2 \\\\[1cm]%
\\end{center}}%
\\vspace*{-1.5cm}%
"LaTeX code for the month header")
(defvar cal-tex-cal-multi-month
"\\def\\calmonth#1#2#3#4%
{\\begin{center}%
\\Huge\\bf #1 #2---#3 #4\\\\[1cm]%
\\end{center}}%
\\vspace*{-1.5cm}%
"LaTeX code for the month header")
(defvar cal-tex-myday
"\\renewcommand{\\myday}[1]%
{\\makebox[\\cellwidth]{\\hfill\\large\\bf#1\\hfill}}
"LaTeX code for a day heading")
(defvar cal-tex-caldate
"\\fboxsep=0pt
\\long\\def\\caldate#1#2#3#4#5#6{%
\\fbox{\\hbox to\\cellwidth{%
\\vbox to\\cellheight{%
\\hbox to\\cellwidth{%
{\\hspace*{1mm}\\Large \\bf \\strut #2}\\hspace{.05\\cellwidth}%
\\raisebox{\\holidaymult\\cellheight}%
{\\parbox[t]{.75\\cellwidth}{\\tiny \\raggedright #4}}}
\\hbox to\\cellwidth{%
\\hspace*{1mm}\\parbox{.95\\cellwidth}{\\tiny \\raggedright #3}}
\\hspace*{1mm}%
\\hbox to\\cellwidth{#6}%
\\vfill%
\\hbox to\\cellwidth{\\hfill \\tiny #5 \\hfill}%
\\vskip 1.4pt}%
\\hskip -0.4pt}}}
"LaTeX code to insert one box with date info in calendar.
This definition is the heart of the calendar!")
(defun cal-tex-list-holidays (d1 d2)
"Generate a list of all holidays from absolute date D1 to D2."
(let* ((result nil)
(start (calendar-gregorian-from-absolute d1))
(start-month (extract-calendar-month start))
(start-year (extract-calendar-year start)))
(increment-calendar-month start-month start-year 1)
(let* ((end (calendar-gregorian-from-absolute d2))
(end-month (extract-calendar-month end))
(end-year (extract-calendar-year end)))
(if (= (extract-calendar-day end) 1)
(increment-calendar-month end-month end-year -1))
(let* ((s (calendar-absolute-from-gregorian
(list start-month 1 start-year)))
(e (calendar-absolute-from-gregorian
(list end-month 1 end-year)))
(d s)
(never t)
(displayed-month start-month)
(displayed-year start-year))
(while (or never (<= d e))
(setq result (append result (calendar-holiday-list)))
(setq never nil)
(increment-calendar-month displayed-month displayed-year 3)
(setq d (calendar-absolute-from-gregorian
(list displayed-month 1 displayed-year))))))
(let ((in-range)
(p result))
(while p
(and (car (car p))
(let ((a (calendar-absolute-from-gregorian (car (car p)))))
(and (<= d1 a) (<= a d2)))
(setq in-range (append (list (car p)) in-range)))
(setq p (cdr p)))
in-range)))
(defun cal-tex-list-diary-entries (d1 d2)
"Generate a list of all diary-entries from absolute date D1 to D2."
(let ((diary-display-hook nil))
(list-diary-entries
(calendar-gregorian-from-absolute d1)
(1+ (- d2 d1)))))
(defun cal-tex-preamble (&optional args)
"Insert the LaTeX preamble.
Preamble Includes initial definitions for various LaTeX commands.
Optional ARGS are included."
(set-buffer (get-buffer-create cal-tex-buffer))
(erase-buffer)
(insert "\\documentstyle")
(if args
(insert "[" args "]"))
(insert "{article}\n"
"\\hbadness 20000
\\hfuzz=1000pt
\\vbadness 20000
\\marginparwidth 0pt
\\oddsidemargin -2cm
\\evensidemargin -2cm
\\marginparsep 0pt
\\topmargin 0pt
\\textwidth 7.5in
\\textheight 9.5in
\\newlength{\\cellwidth}
\\newlength{\\cellheight}
\\newlength{\\boxwidth}
\\newlength{\\boxheight}
\\newlength{\\cellsize}
\\newcommand{\\myday}[1]{}
\\newcommand{\\caldate}[6]{}
\\newcommand{\\nocaldate}[6]{}
\\newcommand{\\calsmall}[6]{}
;;; Yearly calendars
(defun cal-tex-cursor-year (&optional arg)
"Make a buffer with LaTeX commands for the year cursor is on.
Optional prefix argument specifies number of years."
(interactive "P")
(cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
(if arg arg 1)))
(defun cal-tex-cursor-year-landscape (&optional arg)
"Make a buffer with LaTeX commands for the year cursor is on.
Optional prefix argument specifies number of years."
(interactive "P")
(cal-tex-year (extract-calendar-year (calendar-cursor-to-date t))
(if arg arg 1)
t))
(defun cal-tex-year (year n &optional l